package com.woniuxy.util;

import java.util.ArrayList;
import java.util.List;

import com.woniuxy.entity.User;

public class PageUtil {
	
	private static PageUtil pageUtil = null; 
	
	private PageUtil(){
		
	}
	
	public static PageUtil getIntance(){
		if(pageUtil == null)
			pageUtil = new PageUtil();
		return pageUtil;
	}
	
	private static List<User> users;
	
	private List<User> show;
	
	private int page;
	private int pageMax = 1;
	
	public static List<User> getUsers() {
		return users;
	}
	public static void setUsers(List<User> users) {
		PageUtil.users = users;
	}	
	
	public List<User> getShow() {
		setShow();
		System.out.println("Page+++++++"+show.size());
		
		List<User> list = show;
		show = null;
		return list;
	}
	public void setShow() {
		
		show = new ArrayList<User>();
		int now = (page-1)*pageMax;
		
		System.out.println("now:"+now);
		
		for(int i = now;i<users.size()&&i<now+pageMax;i++){
			show.add(users.get(i));
		}
	}
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		if(page >=1 && page <= this.getTotalpage())
			this.page = page;
	}
	public int getTotalpage() {
		System.out.println("Total():"+users.size());
		int all = users.size()/pageMax;
		all = users.size()%pageMax ==0 ? all : all++;
		return all;
	}
	
	public boolean isHead(){
		if(page == 1)
			return true;
		else
			return false;
	}
	public boolean isEnd(){
		if(page == getTotalpage())
			return true;
		else
			return false;
	}
}
